package com.yilian.coach.common.dbsource;

import java.beans.PropertyEditorSupport;

import com.yilian.coach.common.util.EncryptionUtil;

public class JdbcPropertyEditor extends PropertyEditorSupport {
	
	/**
	 * @param text
	 * @throws IllegalArgumentException
	 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
	 */
	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		if (text.startsWith("ENC|")) {
			String content = text.substring(text.indexOf("|") + 1);
			String eData = EncryptionUtil.decodeWithHexStrNoDigest(content);
			super.setValue(eData);
		} else {
			super.setValue(text);
		}
	}
	
	/**
	 * @return
	 * @see java.beans.PropertyEditorSupport#getAsText()
	 */
	@Override
	public String getAsText() {
		return super.getAsText();
	}
	
	/**
	 * @return
	 * @see java.beans.PropertyEditorSupport#getValue()
	 */
	@Override
	public Object getValue() {
		return super.getValue();
	}
	
}
